package cse.om.object;

import cse.om.common.Tagger;
import cse.om.common.Utils;
import cse.om.data.Comment;
import cse.om.spellchecker.Checker;
import cse.om.vswn.Sensitivity;
import cse.om.vswn.VietSentiWordNet;
import edu.stanford.nlp.ling.WordTag;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ProfileAnalyze {

	private final Long profileId;
	private final Date timeFrom, timeTo;
	private List<Comment> listComments;
	private List<String> listContents;
	private List<String> normalizedStrings;
	private List<String> taggedStrings;
	private List<List<WordTag>> taggedWordTags;
	private List<Sensitivity> sensitivities;

	public ProfileAnalyze(Long profileId, Date timeFrom, Date timeTo) {
		this.profileId = profileId;
		this.timeFrom = timeFrom;
		this.timeTo = timeTo;
	}

	public void analyse() {
		listComments = Utils.getCommentsFromDatabase(profileId, timeFrom, timeTo);
		listContents = Utils.getCommentContent(listComments);
		normalizedStrings = new ArrayList<>();
		for (String s : listContents) {
			normalizedStrings.add(Checker.correctSentence(s));
		}
		
		taggedWordTags = new ArrayList<>();
		for (String s : normalizedStrings) {
			taggedWordTags.addAll(Tagger.tagLine(s));
		}
		
		taggedStrings = new ArrayList<>();
		for (List<WordTag> lwt : taggedWordTags) {
			StringBuilder sb = new StringBuilder();
			for (WordTag wt : lwt) {
				sb.append(wt.toString().replace(' ', '_')).append(' ');
			}
			taggedStrings.add(sb.toString().trim());
		}
		
		sensitivities = VietSentiWordNet.extract(taggedWordTags);
	}

	public Long getProfileId() {
		return profileId;
	}

	public Date getTimeFrom() {
		return timeFrom;
	}

	public Date getTimeTo() {
		return timeTo;
	}

	public List<String> getCommentContents() {
		return listContents;
	}

	public List<String> getNormalizedStrings() {
		return normalizedStrings;
	}

	public List<String> getTaggedStrings() {
		return taggedStrings;
	}
	
	public List<List<WordTag>> getTaggedWordTags() {
		return taggedWordTags;
	}
	
	public List<Sensitivity> getSensitivityList() {
		return sensitivities;
	}
}
